home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / COMUTL.C < prev    next >
C/C++ Source or Header  |  1991-10-29  |  5KB  |  142 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/users/jinx/microcode/RCS/comutl.c,v 1.21 1991/10/29 22:55:11 jinx Exp $
  4.  
  5. Copyright (c) 1987-91 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* Compiled Code Utilities */
  36.  
  37. #include "scheme.h"
  38. #include "prims.h"
  39.  
  40. extern SCHEME_OBJECT
  41.   * EXFUN (compiled_entry_to_block_address, (SCHEME_OBJECT));
  42.  
  43. extern long
  44.   EXFUN (compiled_entry_to_block_offset, (SCHEME_OBJECT)),
  45.   EXFUN (coerce_to_compiled, (SCHEME_OBJECT, long, SCHEME_OBJECT *));
  46.  
  47. extern void EXFUN (compiled_entry_type, (SCHEME_OBJECT, long *));
  48.  
  49. DEFINE_PRIMITIVE ("COMPILED-CODE-ADDRESS->BLOCK", Prim_comp_code_address_block, 1, 1,
  50.   "Given a compiled code address, return its compiled code block.")
  51. {
  52.   PRIMITIVE_HEADER (1);
  53.  
  54.   CHECK_ARG (1, COMPILED_CODE_ADDRESS_P);
  55.   PRIMITIVE_RETURN
  56.     (MAKE_POINTER_OBJECT
  57.      (TC_COMPILED_CODE_BLOCK,
  58.       (compiled_entry_to_block_address (ARG_REF (1)))));
  59. }
  60.  
  61. DEFINE_PRIMITIVE ("COMPILED-CODE-ADDRESS->OFFSET", Prim_comp_code_address_offset, 1, 1,
  62.   "Given a compiled code address, return its offset into its block.")
  63. {
  64.   PRIMITIVE_HEADER (1);
  65.   CHECK_ARG (1, COMPILED_CODE_ADDRESS_P);
  66.   PRIMITIVE_RETURN
  67.     (LONG_TO_FIXNUM (compiled_entry_to_block_offset (ARG_REF (1))));
  68. }
  69.  
  70. #ifndef USE_STACKLETS
  71.  
  72. DEFINE_PRIMITIVE ("STACK-TOP-ADDRESS", Prim_stack_top_address, 0, 0, 0)
  73. {
  74.   PRIMITIVE_HEADER (0);
  75.   PRIMITIVE_RETURN (long_to_integer ((long) (ADDRESS_TO_DATUM (Stack_Top))));
  76. }
  77.  
  78. DEFINE_PRIMITIVE ("STACK-ADDRESS-OFFSET", Prim_stack_address_offset, 1, 1, 0)
  79. {
  80.   PRIMITIVE_HEADER (1);
  81.  
  82.   CHECK_ARG (1, STACK_ADDRESS_P);
  83.   PRIMITIVE_RETURN
  84.     (long_to_integer
  85.      (STACK_LOCATIVE_DIFFERENCE ((Stack_Top),
  86.                  (OBJECT_ADDRESS (ARG_REF (1))))));
  87. }
  88.  
  89. #endif /* USE_STACKLETS */
  90.  
  91. DEFINE_PRIMITIVE ("COMPILED-ENTRY-KIND", Prim_compiled_entry_type, 1, 1, 0)
  92. {
  93.   PRIMITIVE_HEADER (1);
  94.   CHECK_ARG (1, COMPILED_CODE_ADDRESS_P);
  95.   {
  96.     long results [3];
  97.     compiled_entry_type ((ARG_REF (1)), results);
  98.     PRIMITIVE_RETURN
  99.       (hunk3_cons ((LONG_TO_FIXNUM (results [0])),
  100.            (LONG_TO_FIXNUM (results [1])),
  101.            (LONG_TO_FIXNUM (results [2]))));
  102.   }
  103. }
  104.  
  105. DEFINE_PRIMITIVE ("COERCE-TO-COMPILED-PROCEDURE", Prim_coerce_to_closure, 2, 2, 0)
  106. {
  107.   SCHEME_OBJECT temp;
  108.   long result;
  109.   PRIMITIVE_HEADER(2);
  110.   result = (coerce_to_compiled ((ARG_REF (1)), (arg_integer (2)), &temp));
  111.   switch(result)
  112.   {
  113.     case PRIM_DONE:
  114.       PRIMITIVE_RETURN(temp);
  115.  
  116.     case PRIM_INTERRUPT:
  117.       Primitive_GC(10);
  118.       /*NOTREACHED*/
  119.  
  120.     default:
  121.       error_bad_range_arg (2);
  122.       /*NOTREACHED*/
  123.   }
  124. }
  125.  
  126. DEFINE_PRIMITIVE ("COMPILED-CLOSURE->ENTRY", Prim_compiled_closure_to_entry, 1, 1,
  127.   "Given a compiled closure, return the entry point which it invokes.")
  128. {
  129.   long entry_type [3];
  130.   SCHEME_OBJECT closure;
  131.   extern long EXFUN (compiled_entry_closure_p, (SCHEME_OBJECT));
  132.   extern SCHEME_OBJECT EXFUN (compiled_closure_to_entry, (SCHEME_OBJECT));
  133.   PRIMITIVE_HEADER (1);
  134.  
  135.   CHECK_ARG (1, COMPILED_CODE_ADDRESS_P);
  136.   closure = (ARG_REF (1));
  137.   compiled_entry_type (closure, (& (entry_type [0])));
  138.   if (! (((entry_type [0]) == 0) && (compiled_entry_closure_p (closure))))
  139.     error_bad_range_arg (1);
  140.   PRIMITIVE_RETURN (compiled_closure_to_entry (closure));
  141. }
  142.